﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using QLKHACHHANG.DataAccess;

namespace QLKHACHHANG
{
    public partial class frmLogin : DevExpress.XtraEditors.XtraForm
    {
        public frmLogin()
        {
            InitializeComponent();
        }

        private void btSettings_Click(object sender, EventArgs e)
        {
            frmConnectServer srv = new frmConnectServer();
            srv.ShowDialog();
        }

        private void btExit_Click(object sender, EventArgs e)
        {
            this.Dispose();
        }

        private void btLogin_Click(object sender, EventArgs e)
        {  
            DevExpress.XtraSplashScreen.SplashScreenManager.ShowForm(typeof(WaitForm1));
            if (!DBUser.CheckUser(tbUser.Text, tbPass.Text))
            {
                MessageBox.Show("Đăng nhập không thành công, vui lòng kiểm tra lại thông tin đăng nhập !");
            }
            else
            {
                this.Hide();
                // thuc thi form chinh
                SetConfig.setAppSetting("Username", tbUser.Text);
                frmMainForm main = new frmMainForm();
                main.Show();
               
            }
            DevExpress.XtraSplashScreen.SplashScreenManager.CloseForm();
            
        }
    
        private void tbUser_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
            {
                tbPass.Focus();
            }
        }

        private void tbPass_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
            {
                btLogin_Click(sender, e);
            }
        }
    }
}